package com.analyse.stock.model;

import com.analyse.stock.enums.MarketEnum;
import com.analyse.stock.vo.TickerVO;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.util.Date;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("t_stock_info")
public class StockInfoModel  extends BaseModel<StockInfoModel> {

    //股票代码 例如：600519（贵州茅台）、AAPL（苹果）。
    private String stockCode;

    // 市场编码，0-深圳证券市场，1-上海证券市场，2-北京证券市场
    private String markCode;
    private String shortMarkCode;

    private String stockName;

    //是否活跃。0：不活跃，1：活跃，2：所有。判断标准：近1个月是否有交易。默认：2。
    private Integer active;

    //交易所代码  例如：XSHG（上交所）、XSHE（深交所）、XNAS（纳斯达克）。
    private String exchangeCode;

    //国家或地区代码
    private String countryCode;

    //币种代码
    private String currencyCode;

    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date upMarketDate;

    //数据拉取时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date dataPullDate;

    //市值
    private BigDecimal markValue;

    //流通市值
    private BigDecimal tradeMv;

    // 总股本
    private BigDecimal capitalStock;

    // 流通股本
    private BigDecimal tradeCapitalStock;

    //市净率
    private BigDecimal pbRate;

    //地域板块codes,多个逗号分隔 如广东板块
    private String regionBoardCodes;

    //概念板块codes,多个逗号分隔
    private String conceptBoardCodes;

    //行业板块codes,多个逗号分隔，如软件开发
    private String industryBoardCodes;

    //所属题材，如标准普尔，富时罗素，深股通，机构重仓
    private String subjectMatter;

    @TableField(exist = false)
    private String boardName;

    public static StockInfoModel transStockInfoModel(TickerVO vo){
        StockInfoModel model = new StockInfoModel();
        model.setMarkCode(MarketEnum.getByName(vo.getExchangeCode()));
        model.setStockCode(vo.getTicker());
        model.setStockName(vo.getName());
        model.setActive(vo.getIsActive());
        model.setCurrencyCode(vo.getCurrencyCode());
        model.setCountryCode(vo.getCountryCode());
        model.setExchangeCode(vo.getExchangeCode());
        model.setUpdateTime(new Date());
        model.setCreateTime(new Date());
        return model;
    }
}
